package com.sky.agent.controller;

import com.sky.agent.entity.UmcAppDeviceToken;
import com.sky.agent.entity.UmcAppPushMsg;
import com.sky.agent.service.AppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/app")
public class AppController {

    @Resource
    private AppService appService;

    @PostMapping("/saveDeviceToken")
    public Map saveDeviceToken(@RequestBody UmcAppDeviceToken appDeviceToken) {
        return appService.saveDeviceToken(appDeviceToken);
    }

    @PostMapping("/pushMsg")
    public Map pushMsg(@RequestBody UmcAppPushMsg appPushMsg) {
        return appService.pushMsg(appPushMsg);
//        Map<String , Object > map = new HashMap<>();
//        try {
//            String url = "http://127.0.0.1:9948/sky_hrm_20250711/app/saveDeviceToken";
//            Map<String, String> paramsMap = new HashMap<>();
//            paramsMap.put("account", appDeviceToken.getAccount());
//            paramsMap.put("deviceToken", appDeviceToken.getDeviceToken());
//            okhttp3.Response response = OkHttp3Util.doPost(url, paramsMap,5000, 3);
//            String result = response.body().string();
//            if (StringUtils.isNotBlank(result)) {
//                JSONObject resultJson = JSONObject.parseObject(result);
//
//                map.put("code", resultJson.getInteger("code"));
//                map.put("message", resultJson.getString("message"));
//            }
//        } catch (IOException e) {
//            log.error("Exception : {}" , e);
//            map.put("code", 500);
//            map.put("message", "系统异常，请联系管理员！");
//        }
//        return map;
    }

//    @PostMapping("/pushMsg")
//    public Map pushMsg(@RequestBody UmcAppDeviceToken appDeviceToken) {
//        umcAppDeviceTokenService.pushMsg(appDeviceToken);
//        return Result.success(mapKey);
//    }
}
